package com.twu.biblioteca;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintStream;
import java.util.ArrayList;

/**
 * Created by kpradhan on 3/10/14.
 */
public class Biblioteca {
    private PrintStream out;
    private BufferedReader in;
    private Library library;
    private Menu menu;

    public Biblioteca(PrintStream out, BufferedReader in, Library library, Menu menu) {
        this.out = out;
        this.in = in;
        this.library = library;
        this.menu = menu;
    }

    public void run() throws IOException {
        start();
        String input = getInput();
        performMenuOption(input);
    }

    public void start() throws IOException {
        out.println("Welcome to Biblioteca");
        out.println(library.toString());
        out.println(menu.toString());
    }

    public String getInput() throws IOException {
        out.println("Enter your selection");
        return in.readLine();
    }

    public void performMenuOption(String input) throws IOException {
        while(!input.equals("1")){
            out.println("Select a valid option!");
            input = getInput();
        }
        int integerInput = Integer.parseInt(input);
        if (menu.getOption(integerInput).equals("List Books")) {
            out.println(library.toString());
        }
    }
}
